#include <iostream>
#include <math.h>
#include <iostream>
#include <set>
using std::cout;
using std::endl;
using std::set;
using std::ostream;
using std::less;

template <typename Container>
void display(const Container& con){
    for(auto & elem : con){
        cout << elem << " ";
    }
    cout << endl;
}

class Point{
public:
    Point(int x = 0,int y = 0)
        :_ix(x)
         ,_iy(y)
    {}

    ~Point(){}

    double getDistence()const{
        return hypot(_ix,_iy);
    }

    int getX()const{
        return _ix;
    }

    int getY()const{
        return _iy;
    }

    friend    
        bool operator<(const Point &lhs,const Point &rhs);

    friend
        ostream &operator<<(ostream &os,const Point &rhs);
private:
    int _ix;
    int _iy;
};

ostream &operator<<(ostream &os,const Point &rhs){
    os << "(" << rhs._ix 
        << "," << rhs._iy
        << ")";
    return os;
}

struct ComparePoint
{
    bool operator()(const Point &lhs,const Point &rhs)const{
        cout << "struct ComparePoint" << endl;
        if(lhs.getDistence() < rhs.getDistence()){
            return true;
        }else if(lhs.getDistence() == rhs.getDistence()){
            if(lhs.getX() < rhs.getX()){
                return true;
            }else if(lhs.getX() == rhs.getX()){
                if(lhs.getY() < rhs.getY()){
                    return true;
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }else{
            return false;
        }
    }

};

//重载运算符
/* bool operator<(const Point &lhs,const Point &rhs){ */
/*     cout << "bool operator<()" << endl; */
/*     if(lhs.getDistence() < rhs.getDistence()){ */
/*         return true; */
/*     }else if(lhs.getDistence() == rhs.getDistence()){ */
/*         if(lhs.getX() < rhs.getX()){ */
/*             return true; */
/*         }else if(lhs.getX() == rhs.getX()){ */
/*             if(lhs.getY() < rhs.getY()){ */
/*                 return true; */
/*             }else{ */
/*                 return false; */
/*             } */
/*         }else{ */
/*             return false; */
/*         } */
/*     }else{ */
/*         return false; */
/*     } */
/* } */

//模板特化
/* namespace std{ */
/* template<> */
/* struct less<Point> */
/* { */

/*     bool operator()(const Point &lhs,const Point &rhs)const{ */
/*         cout << "template<>" << endl; */
/*         if(lhs.getDistence() < rhs.getDistence()){ */
/*             return true; */
/*         }else if(lhs.getDistence() == rhs.getDistence()){ */
/*             if(lhs.getX() < rhs.getX()){ */
/*                 return true; */
/*             }else if(lhs.getX() == rhs.getX()){ */
/*                 if(lhs.getY() < rhs.getY()){ */
/*                     return true; */
/*                 }else{ */
/*                     return false; */
/*                 } */
/*             }else{ */
/*                 return false; */
/*             } */
/*         }else{ */
/*             return false; */
/*         } */
/*     } */

/* }; */
/* } */

void test0(){
    /* set<Point> number = { */
        set<Point,ComparePoint> number = {
        Point(1,2),
        Point(1,-2),
        Point(-1,2),
        Point(10,10),
        Point(2,3),
        Point(3,2),
        Point(2,3),
    };
    display(number);
    }

    int main(int argc, char * argv[])
    {
        test0();
        return 0;
    }


